package com.erp.order.controller;

import com.erp.order.domain.bo.ErpSellerStoreNotautoProductSkuBo;
import com.erp.order.domain.vo.ErpSellerStoreNotautoProductSkuVo;
import com.erp.order.service.IErpSellerStoreNotautoProductSkuService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 店铺不自动化管理商品sku
 *
 * @author erp
 * @date 2024-02-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/seller/sellerStoreNotautoProductSku")
public class ErpSellerStoreNotautoProductSkuController extends BaseController {

    private final IErpSellerStoreNotautoProductSkuService iErpSellerStoreNotautoProductSkuService;

    /**
     * 查询店铺不自动化管理商品sku列表
     */
    @GetMapping("/list")
    public TableDataInfo<ErpSellerStoreNotautoProductSkuVo> list(ErpSellerStoreNotautoProductSkuBo bo, PageQuery pageQuery) {
        return iErpSellerStoreNotautoProductSkuService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出店铺不自动化管理商品sku列表
     */
    @Log(title = "店铺不自动化管理商品sku", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ErpSellerStoreNotautoProductSkuBo bo, HttpServletResponse response) {
        List<ErpSellerStoreNotautoProductSkuVo> list = iErpSellerStoreNotautoProductSkuService.queryList(bo);
//        ExcelUtil.exportExcel(list, "店铺不自动化管理商品sku", ErpSellerStoreNotautoProductSkuVo.class, response);
    }

    /**
     * 获取店铺不自动化管理商品sku详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<ErpSellerStoreNotautoProductSkuVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpSellerStoreNotautoProductSkuService.queryById(id));
    }

    /**
     * 新增店铺不自动化管理商品sku
     */
    @Log(title = "店铺不自动化管理商品sku", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSellerStoreNotautoProductSkuBo bo) {
        return toAjax(iErpSellerStoreNotautoProductSkuService.insertByBo(bo));
    }

    /**
     * 修改店铺不自动化管理商品sku
     */
    @Log(title = "店铺不自动化管理商品sku", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerStoreNotautoProductSkuBo bo) {
        return toAjax(iErpSellerStoreNotautoProductSkuService.updateByBo(bo));
    }

    /**
     * 删除店铺不自动化管理商品sku
     *
     * @param ids 主键串
     */
    @Log(title = "店铺不自动化管理商品sku", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpSellerStoreNotautoProductSkuService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    @GetMapping("/insertBatchSkuCode")
    public R<Object> insertBatchSkuCode(String skuCodes,Long storeId, String storeUserName) {
        return iErpSellerStoreNotautoProductSkuService.insertBatchSkuCode(skuCodes,storeId, storeUserName);
    }

}
